<?php
/**
 * File: polymerkeywords.php.
 * Author: zhouzhe@haibao.com
 * Editor: PhpStorm
 * Date: 16/8/3 下午12:29
 * Brief:
 */
namespace haibao\cms\business;


use \haibao\cms\data\PolymerKeywords as PolymerKeywordsData;
use haibao\frame\data\query\Condition;

class PolymerKeywords extends \haibao\cms\business\Base {
	public static function addPolymerKeyword($model){
		$model->CreateBy = self::getCurrentUser()->Id;
		$data = new PolymerKeywordsData();
		$data->add($model);
		
		$data->delKeywordCache();
	}

	public static function checkKeywordExist($keyword,$keywordId = 0){
		$filter = new \haibao\cms\model\filter\PolymerKeywords();
		$filter->where($filter::CONDITION_FIELD_NAME_KEYWORD,Condition::CONDITION_EQUAL,$keyword);
		if($keywordId){
			$filter->where($filter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_NOTEQUAL,$keywordId);
		}
		$filter->where($filter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_NOTEQUAL,\haibao\cms\model\data\PolymerKeywords::STATUS_DELETE);
		$data = new PolymerKeywordsData();
		return $data->getOne($filter);
	}

	public static function getAll($query){
		$data = new PolymerKeywordsData();
		return $data->getAll($query);
	}

	public static function getOneById($id){
		$data = new PolymerKeywordsData();
		return $data->getOneById($id);
	}

	public static function updateById($id,$arrSet){
		$data = new PolymerKeywordsData();
		return $data->updateById($id,$arrSet);
		
		$data->delKeywordCache();
	}

	public static function deleteKeywordById($id){
		$data = new PolymerKeywordsData();
		$arrSet = array('Status'=>\haibao\cms\model\data\PolymerKeywords::STATUS_DELETE);
		$data->updateById($id,$arrSet);
		
		$data->delKeywordCache();
	}
	
	public static function getKeywordsByTagId($tagId){
		$data = new PolymerKeywordsData();
		return $data->getKeywordsByTagId($tagId);
	}
	
	public static function getKeywordsList(){
		$data = new PolymerKeywordsData();
		return $data->getKeywordsList();
	}

	public static function getKeywordsByName($keyword){
		
		if(!$keyword) throw new BusinessException('关键词为空');
		$data = new PolymerKeywordsData();
		return $data->getKeywordsByName($keyword);
	}

}